<template>
  <div class="con1">
    <img class="fanhui"
         src="@/assets/img/right3.png"
         alt=""
         @click="fanhui" />
    <div class="title">重置密码</div>
    <div class="ipo">
      <img src="@/assets/img/login/ipo.png"
           alt="" />
      <input type="text"
             placeholder="请输入手机号"
             maxlength="11"
             v-model="phone" />
    </div>
    <div class="yanzheng">
      <input type="text"
             placeholder="请输入验证码"
             maxlength="6"
             v-model="code" />
      <div class="daoji">
        <span v-show="show"
              @click="getCode">获取短信验证码</span>
        <span v-show="!show"
              class="count">{{ count }} s</span>
      </div>
    </div>
    <div class="ipo">
      <img src="@/assets/img/login/bass.png"
           alt="" />
      <input type="password"
             placeholder="请输入6-20位密码"
             maxlength="20"
             v-model="pass" />
    </div>
    <div class="ipo">
      <img src="@/assets/img/login/bass.png"
           alt="" />
      <input type="password"
             placeholder="请再次输入密码"
             maxlength="20"
             v-model="repass" />
    </div>
    <!-- <div class="xieyi">
      <label for="ab2"
             class="lab">
        <input id="ab2"
               type="checkbox"
               v-model="dis" />
        我已阅读并同意
      </label>
      <span @click.stop="xieyi">《中铁用户协议》</span>和<span>《隐私政策声明》</span>
    </div> -->
    <div class="denglu"
         @click="zhuce">重置密码</div>
  </div>
</template>

<script>
export default {
  name: "",
  data() {
    return {
      show: true, //显示倒计时
      count: "", //倒计时时间
      timer: null, //倒计时事件
      phone: '',
      code: '',
      pass: '',
      repass: ''
    };
  },
  methods: {
    zhuce() {
      if (this.phone == '') {
        this.$message.error('请输入手机号')
      } else if (this.code == '') {
        this.$message.error('请输入验证码')
      } else if (this.pass == '') {
        this.$message.error('请输入密码')
      } else if (!/^[1][3,4,5,6,7,8,9][0-9]{9}$/.test(this.phone)) {
        this.$message.error('手机号格式错误')
      } else if (!/^[0-9]{4,6}$/.test(this.code)) {
        this.$message.error('验证码格式错误')
      } else if (!/^[a-zA-Z0-9_-`~!@#$%^&*]{6,20}$/.test(this.pass)) {
        this.$message.error('密码格式错误')
      } else if (this.pass != this.repass) {
        this.$message.error('两次密码不一致')
      } else {
        this.$postRequest('/api/user/forgetPassword', {
          phone: this.phone,
          newPassword: this.pass,
          code: this.code
        }).then(res => {
          this.$message.success('修改成功')
          this.$router.push({ name: 'loginindex' })
        })
      }
    },
    //倒计时
    getCode() {
      if (!this.show) return;
      const TIME_COUNT = 60;
      if (!this.timer) {
        if (this.phone == '') {
          this.$message.error('请输入手机号')
        } else if (!/^[1][3,4,5,6,7,8,9][0-9]{9}$/.test(this.phone)) {
          this.$message.error('手机号格式错误')
        } else {
          this.count = TIME_COUNT;
          this.show = false;
          this.timer = setInterval(() => {
            if (this.count > 0 && this.count <= TIME_COUNT) {
              this.count--;
            } else {
              this.show = true;
              clearInterval(this.timer);
              this.timer = null;
            }
          }, 1000);
          this.$postRequest('/api/member/getCode', {
            phone: this.phone
          }).then(res => {

          })
        }
      }
    },
    fanhui() {
      this.$router.go(-1); //返回上一层
    },
    xieyi(num) {
      if (num == 1) {

      } else {

      }
    }
  }
};
</script>
<style scoped lang="scss">
.con1 {
  height: 100%;
  width: 100%;
  display: flex;
  flex-flow: column nowrap;
  align-items: center;
  overflow-y: scroll;
  .fanhui {
    flex-shrink: 0;
    width: 18px;
    height: 24px;
    margin-top: 40px;
    margin-left: 40px;
    transform: rotate(180deg);
    align-self: flex-start;
    padding: 5px;
    cursor: pointer;
  }
  .title {
    flex-shrink: 0;
    margin-top: 55px;
    width: 70%;
    font-size: 32px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #000000;
    margin-bottom: 50px;
  }
  .ipo {
    flex-shrink: 0;
    height: 105px;
    width: 70%;
    display: flex;
    align-items: center;
    position: relative;
    img {
      width: 25px;
      height: 25px;
      position: absolute;
      top: 50%;
      transform: translate(0, -50%);
      left: 20px;
    }
    input {
      width: 100%;
      height: 100%;
      border: none;
      border-bottom: 1px solid #e5e5e5;
      outline: none;
      padding-left: 76px;
      font-size: 24px;
      font-family: PingFang SC;
      font-weight: 500;
      color: #1b1b1b;
      box-sizing: border-box;
      &:focus {
        border: none;
        border-bottom: 1px solid #1a69e0;
      }
      &::-webkit-input-placeholder {
        color: #bfbfbf;
      }
    }
  }
  .yanzheng {
    flex-shrink: 0;
    height: 105px;
    width: 70%;
    display: flex;
    align-items: center;
    position: relative;
    input {
      width: 100%;
      height: 100%;
      border: none;
      border-bottom: 1px solid #e5e5e5;
      outline: none;
      padding-left: 20px;
      font-size: 24px;
      font-family: PingFang SC;
      font-weight: 500;
      color: #1b1b1b;
      box-sizing: border-box;
      &:focus {
        border: none;
        border-bottom: 1px solid #1a69e0;
      }
      &::-webkit-input-placeholder {
        color: #bfbfbf;
      }
    }
    .daoji {
      width: 200px;
      height: 50px;
      background: rgba(26, 105, 224, 0.05);
      border: 1px solid #1a69e0;
      position: absolute;
      right: 0px;
      top: 50%;
      transform: translate(0, -50%);
      text-align: center;
      line-height: 50px;
      font-size: 24px;
      font-family: PingFang SC;
      font-weight: 500;
      color: #1a69e0;
      cursor: pointer;
    }
  }
  .xieyi {
    flex-shrink: 0;
    width: 70%;
    height: 60px;
    display: flex;
    align-items: center;
    padding-left: 28px;
    .lab {
      display: flex;
      align-items: center;
      input[type='checkbox'] {
        width: 20px;
        height: 20px;
        display: inline-block;
        text-align: center;
        vertical-align: middle;
        line-height: 18px;
        margin-right: 10px;
        position: relative;
        margin-right: 10px;
      }
      input[type='checkbox']::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        background: #fff;
        width: 100%;
        height: 100%;
        border: 1px solid #d9d9d9;
        border-radius: 4px;
      }
      input[type='checkbox']:checked::before {
        content: '\2713';
        background-color: #fff;
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        border: 1px solid #7d7d7d;
        border-radius: 4px;
        color: #7d7d7d;
        font-size: 20px;
        font-weight: bold;
      }
    }
    span {
      color: #1a69e0;
      cursor: pointer;
    }
  }
  .denglu {
    flex-shrink: 0;
    margin-top: 30px;
    width: 400px;
    height: 60px;
    background: #1a69e0;
    border-radius: 2px;
    line-height: 60px;
    text-align: center;
    font-size: 24px;
    font-family: PingFang SC;
    font-weight: 500;
    color: #ffffff;
    cursor: pointer;
  }
}
</style>